/**
 * payment 实现方式为跳转到一个公共的支付页面
 */
export default class Payment {
    constructor({ api, effects, router }) {
        this.api = api;
        this.effects = effects;
        this.router = router;
    }

    *pay(payload) {
        const redirect = payload.redirect || window.location.href
        const orderNum = payload.orderNum.orderNum || payload.orderNum
        const payUrl = `${
            this.api.WEAPP_DOMAIN
        }/rapp/payment/?orderId=${orderNum}&source=2&redirect=${encodeURIComponent(redirect)}`;
        
        yield this.effects.put.resolve(
            this.router.redirect({
                url: payUrl
            })
        );
    }
}
